package Test;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class TestDemo10 {
    static boolean flags = true;
    public static AtomicBoolean atomicBoolean = new AtomicBoolean(false);

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            while (flags) {
                System.out.println("嘻嘻");
            }
            System.out.println("over");
        },"A").start();
        TimeUnit.MILLISECONDS.sleep(20);
        new Thread(()->{
            flags = false;
            System.out.println("修改成功");
        },"B").start();
        Thread.currentThread().interrupt();
    }
    public static void main1(String[] args) throws InterruptedException {
        new Thread(()->{
            while (true) {
                if(flags) {
                    System.out.println("flags被修改，线程停止");
                    break;
                }
                System.out.println("hello ---- A");
            }
        },"A").start();
        TimeUnit.SECONDS.sleep(5);
        new Thread(()->{
            flags = true;
        },"B").start();
    }
}
